//
//  XSSocketManager.h
//  XSSocketDemo
//
//  Created by xingshuai on 2021/8/12.
//

#import <Foundation/Foundation.h>
// socket头文件
#import <SocketRocket/SocketRocket.h>

NS_ASSUME_NONNULL_BEGIN

@protocol XSSocketRocketToolDelegate <NSObject>
@optional
// 收到id类型消息的回调
- (void)webSocket:(SRWebSocket *_Nullable)webSocket didReceiveMessage:(id _Nullable )message;
// 当服务器拒绝，或者发生错误的时候回调
- (void)webSocket:(SRWebSocket *_Nullable)webSocket didFailWithError:(NSError *_Nullable)error;
// 服务器关闭的时候回调
- (void)webSocket:(SRWebSocket *_Nullable)webSocket didCloseWithCode:(NSInteger)code reason:(nullable NSString *)reason wasClean:(BOOL)wasClean;
// 服务器心跳回调
- (void)webSocket:(SRWebSocket *_Nullable)webSocket didReceivePong:(nullable NSData *)pongData;
// 为yes，则将data转为string，no的时候不进行转换。
- (BOOL)webSocketShouldConvertTextFrameToString:(SRWebSocket *_Nullable)webSocket NS_SWIFT_NAME(webSocketShouldConvertTextFrameToString(_:));
// webSocket已经打开
- (void)webSocketDidOpen:(SRWebSocket *_Nullable)webSocket;
// webSocket已经关闭
- (void)webSocketDidClose:(SRWebSocket *_Nullable)webSocket;
@end;

@interface XSSocketManager : NSObject

// 代理属性
@property(nonatomic,weak) id<XSSocketRocketToolDelegate> delegate;
// socket服务器路径
@property (nonatomic,strong) NSString *wsURLString;
// 直播间id
@property (nonatomic,strong) NSString *liveId;

// 单例对象
+ (instancetype)sharedInstance;

// 连接webSocket
- (void)connect;

// 重连webSocket
- (void)reconnect;

// 关闭WebSocket的连接
- (void)closeWebSocket;

// 发送json数据
- (BOOL)sendString:(NSString *)string error:(NSError **)error;

@end

NS_ASSUME_NONNULL_END
